package com.example.home.pet.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.pet.adapter.InquiryDetailAdapter;
import com.example.home.pet.bean.CaseInquiryBean;
import com.example.home.pet.bean.InquiryDetail;
import com.example.home.tool.OKHttpTool;
import com.google.gson.Gson;

import static com.example.home.tool.StaticActi.ip;

public class CaseInquiryDetail extends AppCompatActivity {

    private ImageView back;
    private ImageView img;
    private TextView name;
    private TextView zhicheng;
    private TextView bianhao;
    private Button btnTiwen;
    private ImageView avatar;
    private TextView question;
    private RecyclerView rcvList;
    CaseInquiryBean.RowsBean rowsBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_case_inquiry_detail);
        Intent intent = getIntent();
        String strCaseInquiryBean = intent.getStringExtra("CaseInquiryBean");

        Gson gson = new Gson();
        rowsBean = gson.fromJson(strCaseInquiryBean, CaseInquiryBean.RowsBean.class);
        initView();

        Glide.with(CaseInquiryDetail.this).load(ip+rowsBean.getDoctor().getAvatar()).into(img);
        name.setText(rowsBean.getDoctor().getName());
        zhicheng.setText("职称："+rowsBean.getDoctor().getJobName());
        bianhao.setText("执业编号："+rowsBean.getDoctor().getPracticeNo());
        Glide.with(CaseInquiryDetail.this).load(ip+rowsBean.getImageUrls()).into(avatar);
        question.setText("问题描述："+rowsBean.getQuestion());

        getData();
        btnTiwen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CaseInquiryDetail.this,DoctorInquiryDetail.class);
                intent.putExtra("CaseInquiryBean",strCaseInquiryBean);
                startActivity(intent);
            }
        });

    }

    private void getData() {
        OKHttpTool.doNetRequest("prod-api/api/pet-hospital/inquiry-message/list?inquiryId="+rowsBean.getDoctor().getTypeId(),
                OKHttpTool.GET,
                InquiryDetail.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        InquiryDetail inquiryDetail = (InquiryDetail) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                bindList(inquiryDetail);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void bindList(InquiryDetail inquiryDetail) {
        InquiryDetailAdapter inquiryDetailAdapter = new InquiryDetailAdapter(CaseInquiryDetail.this,inquiryDetail.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(CaseInquiryDetail.this);
        rcvList.setAdapter(inquiryDetailAdapter);
        rcvList.setLayoutManager(linearLayoutManager);
    }

    private void initView() {

        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CaseInquiryDetail.this.finish();
            }
        });
        img = findViewById(R.id.img);
        name = findViewById(R.id.name);
        zhicheng = findViewById(R.id.zhicheng);
        bianhao = findViewById(R.id.bianhao);
        btnTiwen = findViewById(R.id.btn_tiwen);
        avatar = findViewById(R.id.avatar);
        question = findViewById(R.id.question);
        rcvList = findViewById(R.id.rcv_list);

    }
}